//#region 本地存储的演示部分
let txtInfo = document.getElementById('txtInfo');
let btnLocal = document.getElementById('btnLocal');

btnLocal.addEventListener('click', () => {
  // 保存信息到本地存储，第一个参数是保存的名称，第二个是保存的值（字符串）
  localStorage.setItem('info', txtInfo.value);
  alert('存储成功');
});

// 读取本地存储的信息
txtInfo.value = localStorage.getItem('info');

//#endregion

//#region token的相关
import { ajax } from './ajax.js';

let btnToken = document.getElementById('btnToken');
let spToken = document.getElementById('spToken');

btnToken.addEventListener('click', () => {
  ajax.get('/token', {}, (data) => {
    spToken.innerHTML = JSON.stringify(data);
  });
});

//#endregion

//#region 图片验证的演示

let imgCode = document.getElementById('imgCode');
let acode = document.getElementById('acode');

function loadImgCode() {
  ajax.post('/tool/getImageCode', {}, (data) => {
    if (data.success) {
      imgCode.setAttribute('src', data.message);
    }
  });
}

imgCode.addEventListener('click', loadImgCode);
acode.addEventListener('click', loadImgCode);

loadImgCode();

//#endregion
